package com.lqian.service.emp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.lqian.mapper.DepartMapper;
import com.lqian.mapper.EmployeeMapper;
import com.lqian.pojo.Depart;
import com.lqian.pojo.Employee;
import com.lqian.utils.PageUtil;


@Service
public class EmployeeServiceImpl implements IEmployeeService{
	
	@Autowired
	EmployeeMapper employeeMapper;
	
	@Autowired
	private DepartMapper departMapper;
	

	
	public  List<Employee> getAllEmployee(){
		return employeeMapper.getAllEmployee();
	}



	public Employee login(String ename, String epass) {
		
		return employeeMapper.login(ename, epass);
	}



	public void updatePwd(String epass, Integer eid) {
		employeeMapper.updatePwd(epass, eid);
	}



	/**
	 *select myInfo
	 */
	public Employee getEmployeeWithDept(Integer eideid) {
		return employeeMapper.getEmployeeWithDept(eideid);
	}



	public Integer count() {
		return employeeMapper.count();
	}



	public List<Employee> getEmployeeDept() {
		return employeeMapper.getEmployeeDept();
	}



	public List<Employee> findAllEmpByPage(PageUtil page) {
		return employeeMapper.findAllEmpByPage(page);
	}



	@Override
	public Map<String, Object> findUserByEid(Integer eid) {
		
		Map map=new HashMap<String, Object>();
		
		//获取用户
		Employee emp=employeeMapper.findUserByEid(eid);
		
		//获取部门列表
		List<Depart> departList=departMapper.getAllDepart();
		
		map.put("emp", emp);
		map.put("departList", departList);
		
		return map;
	}



	@Override
	public Integer updateUser(Employee emp) {
		return employeeMapper.updateUser(emp);
	}



	@Override
	public Integer deleteEmployee(Integer eid) {
		return employeeMapper.deleteEmployee(eid);
	}



	@Override
	public Integer resEmployee(Integer eid) {
		return employeeMapper.resEmployee(eid);
	}



	@Override
	public Integer addEmployee(Employee employee) {
		//Employee [eid=null, ename=liuliu, epass=123456, realname=刘德华, esex=0,
		//entrydate=null, leavedate=null, position=null, sal=null, estatus=null, did=6, dname=null]
		
		//POSITION
		employee.setPosition(2);
		//默认激活
		employee.setEstatus(0);
		//默认薪水
		employee.setSal(5000);
		
		return employeeMapper.addEmployee(employee);
	}



	
	

}
